package Entity;
import java.util.Date;
import Controller.DBcontroller;
import java.io.Serializable;

/**
 * This Entity is for prices. every parking lot has it's own parking lot prices.
 * This Entity will be used for knowing the prices of each parking lot.
 * The prices can be changed by the parking lot manager.
 * @author Moran Abilea
 *
 */

public class Prices implements Serializable
{

	private static final long serialVersionUID = 2619999469205946145L;

	/**
	 * is an enum for knowing the errors in case of invalid input.
	 * OCCERR- means an occasional parking place price error (occasional parking place price <0)
	 * ORDERR- means an ordered parking place price error (ordered parking place price <0)
	 * PNUMERR- means an error in parking lot number (parking lot number isn't between 1 to 6)
	 */
public enum pvalidateErrs{OCCERR,ORDERR,PNUMERR}; // this is an enum for setting errors for the validate function.

private double OccasionalParkingPlace; // this is the only price (per hours) that we can change.
private double OrderedParkingPlace; // this is also the only price (per hours) that we can change.
private double MonthlyRegularSubscriber; // the formula for this is: 60*OrderedParkingPlace. 
private double FullMonthlySubscriber; // the formula for this is: 72*OrderedParkingPlace.
private int parkingLotNumber; // this is the parking lot number of the changing prices.
private Date dateOfSubmission; // this is the date of submission, which is relevant only for the parking lot manager.
private double RegularSubscriberForManyCars; // this will be set as 0.9*MonthlyRegularSubscriber.

/**
 * is the constructor of this entity. 
 * it will set the date of submission, a default values for occational parking place price (5 sh) 
 * and for ordered parking place price (4 sh). it will also calculate the other prices as well.
 * @param parknum = in order to know which parking lot prices we will need to handle. 
 */
// This will be the new default constructor for the prices object.
public Prices(int parknum)
{
	this.dateOfSubmission=new Date(); // set the date to today's date.
	this.OccasionalParkingPlace=5; // set this price to his default.
	this.OrderedParkingPlace=4; // set this price to his default.
	this.MonthlyRegularSubscriber=60*this.OrderedParkingPlace; // calculate the price according to the formula.
	this.FullMonthlySubscriber=72*this.OrderedParkingPlace; // calculate the price according to the formula.
	this.parkingLotNumber=parknum; // saving the parking place number. 
	this.RegularSubscriberForManyCars=this.MonthlyRegularSubscriber*0.9;
}

/**
 * is the function for setting new prices. also will calculate the other prices.
 * @param parknum =  in order to know which parking lot prices we will need to handle.
 * @param new1 = the first price (also known as the new occational parking place price).
 * @param new2 = the second price (also known as the new ordered parking place price).
 */
public void setNewPrices(int parknum, double new1, double new2){
	this.OccasionalParkingPlace=new1;
	this.OrderedParkingPlace=new2;
	this.MonthlyRegularSubscriber=60*this.OrderedParkingPlace; // calculate the price according to the formula.
	this.FullMonthlySubscriber=72*this.OrderedParkingPlace; // calculate the price according to the formula.
	this.parkingLotNumber=parknum; // saving the parking place number. 
	this.RegularSubscriberForManyCars=this.MonthlyRegularSubscriber*0.9;
}

// the get functions.
public Date getDateOfSubmission() {return dateOfSubmission;}
public double getFullMonthlySubscriber() {return FullMonthlySubscriber;}
public double getMonthlyRegularSubscriber() {return MonthlyRegularSubscriber;}
public double getOccasionalParkingPlace() {return OccasionalParkingPlace;}
public double getOrderedParkingPlace() {return OrderedParkingPlace;}
public int getParkingLotNumber() {return parkingLotNumber;}
public double getRegularSubscriberForManyCars() {return RegularSubscriberForManyCars;}

// the set functions.
public void setOccasionalParkingPlace(double occasionalParkingPlace) {OccasionalParkingPlace = occasionalParkingPlace;}
public void setOrderedParkingPlace(double orderedParkingPlace) {OrderedParkingPlace = orderedParkingPlace;}
public void setParkingLotNumber(int parkingLotNumber) {parkingLotNumber = parkingLotNumber;}
public void setDateOfSubmission(Date dateOfSubmission) {
	this.dateOfSubmission = dateOfSubmission;
}
/**
 * is the function for validate the input from the parking lot manager.
 * @return which error occurs.(OCCERR for error in occational price, ORDERR for error in the ordered price, PNUMERR for error in parking lot number).
 */
// This function is for validating the vars.
public pvalidateErrs validate()
{
	if(this.OccasionalParkingPlace<=0)
		return pvalidateErrs.OCCERR;
	if(this.OrderedParkingPlace<=0)
		return pvalidateErrs.ORDERR;
	if(this.parkingLotNumber<=0||this.parkingLotNumber>6)
		return pvalidateErrs.PNUMERR;
	return null;
}

/**
 * is the fucntion for saving the prices to DB.
 */
// this function is for saving complaint to the DB.
public void save()
{
	Prices p=new Prices(this.parkingLotNumber);
	DBcontroller.savePricesToDB(p);
}

}